package sum.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import sum.Dao.UserDao;
import sum.Entity.Student;
import sum.Entity.User;
import sum.Service.StudentService;
import sum.Service.TeacherService;
import sum.Service.UserService;

import java.util.List;

@Controller
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    UserService userService;
    @Autowired
    TeacherService teacherService;
    @RequestMapping("/byConditions")
    public String getStudentsByConditions(User user, Model model) {
        List<User> users = userService.queryByConditions(user);
        model.addAttribute("users", users);
        return "user";
    }
    @RequestMapping("/addoneuser")
    public String adduser(User user)
    {
        userService.adduser(user);
        return "user";
    }
    @RequestMapping("/edituser")
    public String manageuser(User user)
    {
        userService.edit(user);
        return "user";
    }
    @RequestMapping("/deleteuser")
    public String deleteuser(User user)
    {
        userService.deleteByName(user.getUsername());
        return "user";
    }
    @RequestMapping("/addonestu")
    public String addstu(Student student)
    {
        teacherService.addone(student);
        return "admin";
    }
    @RequestMapping("/editstu")
    public String managestu(Student student)
    {
        teacherService.edit(student);
        return "admin";
    }
    @RequestMapping("/deletestu")
    public String deletestu(Student student)
    {
        teacherService.deleteByName(student);
        return "admin";
    }
}
